package com.kws.commercial.controller;

import com.github.pagehelper.PageInfo;
import com.kws.commercial.business.UploadEquipmentLedgerBusiness;
import com.kws.commercial.dao.CommercialEquipmentLedger;
import com.kws.commercial.dao.Info.ExportEquipmentLedgerInfo;
import com.kws.commercial.dao.Info.QueryEquipmentLedgerInfo;
import com.kws.commercial.service.CommercialEquipmentLedgerService;
import com.kws.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <b>CommercialEquipmentLedgerController</b>
 *
 * @description: CommercialEquipmentLedgerController <br>
 * @date: 2024/10/30 11:39 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "设备台账模块")
@RestController
public class CommercialEquipmentLedgerController {
    private static final Logger logger = LoggerFactory.getLogger(CommercialEquipmentLedgerController.class);

    @Autowired
    private CommercialEquipmentLedgerService commercialEquipmentLedgerService;

    @Autowired
    private UploadEquipmentLedgerBusiness uploadEquipmentLedgerBusiness;

//    @Autowired
//    private ExportFileDownloadUtil exportFileDownloadUtil;

    @ApiOperation("分页查询设备台账列表")
    @GetMapping("/query/equipmentLedger/page")
    public R<PageInfo<QueryEquipmentLedgerInfo>> queryEquipmentLedgerPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                          @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                          @RequestParam(required = false) String deviceNo,
                                                                          @RequestParam(required = false) String schemeName){
        PageInfo<QueryEquipmentLedgerInfo> pageInfo = commercialEquipmentLedgerService.queryEquipmentLedgerPage(pageNum,pageSize,deviceNo,schemeName);
        return R.ok(pageInfo);
    }

    @ApiOperation("导入设备台账信息")
    @PostMapping("/import/equipmentLedger")
    public R importEquipmentLedger(@RequestParam("file") MultipartFile file){
        List<CommercialEquipmentLedger> commercialEquipmentLedgers = uploadEquipmentLedgerBusiness.uploadList(file);
        boolean status = commercialEquipmentLedgerService.importEquipmentLedger(commercialEquipmentLedgers);
        return R.ok(status);
    }

    @ApiOperation("根据id查询设备详情")
    @GetMapping("/query/equipmentLedger/byId")
    public R<QueryEquipmentLedgerInfo> queryEquipmentLedgerById(@RequestParam Long id){
        QueryEquipmentLedgerInfo info = commercialEquipmentLedgerService.queryEquipmentLedgerById(id);
        return R.ok(info);
    }

    @ApiOperation("导出设备列表")
    @GetMapping("/export/equipmentLedger")
    public R exportEquipmentLedger(){
        List<ExportEquipmentLedgerInfo> equipmentLedgerList = commercialEquipmentLedgerService.queryEquipmentLedgerList();

        return null;
    }
}
